package com.suntront.module_metertask.adapter;

import android.content.Context;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.dinuscxj.progressbar.CircleProgressBar;
import com.google.gson.Gson;
import com.mtjsoft.www.kotlinmvputils.imp.AdapterItemClickListener;
import com.mtjsoft.www.kotlinmvputils.utils.KLog;
import com.suntront.lib_db.table.MeterT;
import com.suntront.module_metertask.R;
import com.suntront.module_metertask.meterlist.MeterListRecycleViewActivity;

import java.util.List;

/**
 * @author mtj
 * @Package com.suntront.module_metertask.adapter
 * @date 2020-05-27 15:03:38
 */

public class MeterListAdapter extends BaseQuickAdapter<MeterT, BaseViewHolder> {

    private Context context;
    private AdapterItemClickListener adapterItemClickListener;
    // type 0: 抄表任务 1：抄表排序
    private int type;

    public MeterListAdapter(Context context, List<MeterT> list, int type, AdapterItemClickListener adapterItemClickListener) {
        super(R.layout.item_metertask, list);
        this.context = context;
        this.type = type;
        this.adapterItemClickListener = adapterItemClickListener;
    }

    @Override
    protected void convert(BaseViewHolder holder, MeterT model) {
        int position = holder.getLayoutPosition();
        CircleProgressBar circleProgressBar = holder.getView(R.id.solid_progress);
        if (model.getUserCount() > 0) {
            circleProgressBar.setProgress((int) (model.getCopyCount() * 100.00 / model.getUserCount()));
        } else {
            circleProgressBar.setProgress(0);
        }
        holder.setText(R.id.mtask_biaocmc, model.getRosterName() + "(" + model.getRosterCode() + ")");
        holder.setText(R.id.mtask_yonghzs, model.getUserCount() + "");
        holder.setText(R.id.mtask_yic, model.getCopyCount() + "");
        //
        if (type == 0) {
            holder.getView(R.id.datasyn_right_arrow1_icon).setOnClickListener(v -> {
                        if (adapterItemClickListener != null) {
                            adapterItemClickListener.onItemClick(position, v);
                        }
                    }
            );
            circleProgressBar.setVisibility(View.VISIBLE);
            holder.getView(R.id.ll_count).setVisibility(View.VISIBLE);
            holder.getView(R.id.datasyn_right_arrow1_icon).setVisibility(View.VISIBLE);
        } else {
            circleProgressBar.setVisibility(View.GONE);
            holder.getView(R.id.ll_count).setVisibility(View.GONE);
            holder.getView(R.id.datasyn_right_arrow1_icon).setVisibility(View.GONE);
            holder.getView(R.id.rl_task_item).setOnClickListener(v -> {
                        if (adapterItemClickListener != null) {
                            adapterItemClickListener.onItemClick(position, v);
                        }
                    }
            );
        }
    }
}